package com.bicon.botu.core.base.common.utils;

import com.alibaba.fastjson.JSON;
import org.apache.commons.collections.map.HashedMap;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by L on 2017/3/29.
 * json串的筛选解析
 */
public class JsonFilterUtil {

    //static Logger logger = Logger.getLogger(JsonFilterUtil.class);

    /**
     * 生成数据库查询格式的Map
     *
     * @param json
     * @return
     */
    public static Map<String, String> filterJson(String json) {
        try{
            if (StringUtils.isEmpty(json)){
                return null;
            }
            Map<String,String> resultMap = new HashedMap();
            Map<String, String> filterMap = JSON.parseObject(json,
                    HashMap.class);
            for (String key : filterMap.keySet()) {
                String value = filterMap.get(key);
                if (key.split("_").length < 2) {
                    resultMap.put("EQ_" + key, value);
                } else {
                    resultMap.put(key, value);
                }
            }
            return resultMap;
        }catch (Exception e){
            //logger.info("出现异常",e);
            return null;
        }

    }

}
